<template>
  <div class="home-view">
    <!-- 页面标题 -->
    <div class="page-header">
      <h2>首页</h2>
      <p>欢迎使用管理系统</p>
    </div>

    <!-- 信息卡片区域 -->
    <div class="info-cards">
      <div class="info-card">
        <div class="card-icon">
          <i class="el-icon-shopping-cart-full"></i>
        </div>
        <div class="card-content">
          <div class="card-title">总订单数</div>
          <div class="card-value">{{ homeData.total_order || 0 }}</div>
        </div>
      </div>

      <div class="info-card">
        <div class="card-icon">
          <i class="el-icon-goods"></i>
        </div>
        <div class="card-content">
          <div class="card-title">总商品数</div>
          <div class="card-value">{{ homeData.total_product || 0 }}</div>
        </div>
      </div>

      <div class="info-card">
        <div class="card-icon">
          <i class="el-icon-menu"></i>
        </div>
        <div class="card-content">
          <div class="card-title">总类别数</div>
          <div class="card-value">{{ homeData.total_category || 0 }}</div>
        </div>
      </div>
    </div>

    <!-- 统计图表区域 -->
    <!-- <div class="chart-section">
      <div class="chart-card">
        <div class="chart-header">
          <h3>数据统计</h3>
        </div>
        <div class="chart-content">
          <div class="chart-placeholder">
            <i class="el-icon-data-line"></i>
            <p>图表区域</p>
            <span>这里可以放置各种统计图表</span>
          </div>
        </div>
      </div>
    </div> -->

    <!-- 快捷操作区域 -->
    <!-- <div class="quick-actions">
      <div class="action-card">
        <div class="action-header">
          <h3>快捷操作</h3>
        </div>
        <div class="action-buttons">
          <el-button type="primary" icon="el-icon-plus" @click="handleQuickAdd">快速添加</el-button>
          <el-button type="success" icon="el-icon-download" @click="handleExport">导出数据</el-button>
          <el-button type="warning" icon="el-icon-refresh" @click="handleRefresh">刷新数据</el-button>
          <el-button type="info" icon="el-icon-setting" @click="handleSettings">系统设置</el-button>
        </div>
      </div>
    </div> -->
  </div>
</template>

<script>
import { getHomeData } from '@/api/contract';

export default {
  name: 'HomeView',
  data() {
    return {
      homeData: {
        total_order: 0,
        total_product: 0,
        total_category: 0
      }
    }
  },
  methods: {
    // 获取首页数据
    async fetchHomeData() {
      try {
        const response = await getHomeData();
        if (response.data.code === 200) {
          this.homeData = response.data.data || {};
        } else {
          this.$message.error(response.data.msg || response.data.message || '获取数据失败');
        }
      } catch (error) {
        console.error('获取首页数据失败:', error);
        this.$message.error('获取数据失败，请稍后重试');
      }
    },
    handleRefresh() {
      this.fetchHomeData();
      this.$message.success('数据已刷新');
    }
  },
  created() {
    this.fetchHomeData();
  }
}
</script>

<style scoped>
.home-view {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 60px);
  box-sizing: border-box;
}

.page-header {
  margin-bottom: 30px;
}

.page-header h2 {
  margin: 0 0 10px 0;
  color: #303133;
  font-size: 24px;
  font-weight: 600;
}

.page-header p {
  margin: 0;
  color: #909399;
  font-size: 14px;
}

.info-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.info-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  padding: 24px;
  color: white;
  display: flex;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.info-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.info-card:nth-child(2) {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.info-card:nth-child(3) {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.card-icon {
  font-size: 48px;
  margin-right: 20px;
  opacity: 0.9;
}

.card-content {
  flex: 1;
}

.card-title {
  font-size: 16px;
  margin-bottom: 8px;
  opacity: 0.9;
}

.card-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
}

.card-action {
  margin-left: 20px;
}

.chart-section {
  margin-bottom: 30px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .home-view {
    padding: 10px;
    min-height: calc(100vh - 50px);
  }
  
  .page-header h2 {
    font-size: 20px;
  }
  
  .info-cards {
    grid-template-columns: 1fr; /* 移动端单列布局 */
    gap: 15px;
  }
  
  .info-card {
    padding: 20px;
  }
  
  .card-icon {
    font-size: 36px;
    margin-right: 15px;
  }
  
  .card-value {
    font-size: 24px;
  }
}

.chart-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.chart-header {
  padding: 20px 24px;
  border-bottom: 1px solid #ebeef5;
  background: #fafafa;
}

.chart-header h3 {
  margin: 0;
  color: #303133;
  font-size: 18px;
  font-weight: 600;
}

.chart-content {
  padding: 40px 24px;
}

.chart-placeholder {
  text-align: center;
  color: #909399;
}

.chart-placeholder i {
  font-size: 64px;
  margin-bottom: 16px;
  display: block;
}

.chart-placeholder p {
  font-size: 18px;
  margin: 0 0 8px 0;
  color: #606266;
}

.chart-placeholder span {
  font-size: 14px;
  color: #909399;
}

.quick-actions {
  margin-bottom: 30px;
}

.action-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.action-header {
  padding: 20px 24px;
  border-bottom: 1px solid #ebeef5;
  background: #fafafa;
}

.action-header h3 {
  margin: 0;
  color: #303133;
  font-size: 18px;
  font-weight: 600;
}

.action-buttons {
  padding: 24px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.action-buttons .el-button {
  min-width: 120px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .info-cards {
    grid-template-columns: 1fr;
  }
  
  .action-buttons {
    flex-direction: column;
  }
  
  .action-buttons .el-button {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .home-view {
    padding: 15px;
  }
  
  .info-card {
    padding: 20px;
  }
  
  .card-icon {
    font-size: 36px;
    margin-right: 16px;
  }
  
  .card-value {
    font-size: 24px;
  }
}
</style>

